﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace DVM
{
    public class DBField
    {
        public HashSet<string> ConstValues = new HashSet<string>();

        public DBField()
        {
            ConstValues = GetConstValues();
        }

        public static DBField GetStatic()
        {
            return new DBField();
        }

        /// <summary>
        /// 查询产品类型Id
        /// </summary>
        public const string ProductTypeId = "ProductTypeId";

        /// <summary>
        /// 查询产品图片Id
        /// </summary>
        public const string ProductImageId = "ProductImageId";


        /// <summary>
        /// 获取当前实体类的所有常量值
        /// </summary>
        /// <returns></returns>

        private HashSet<string> GetConstValues()
        {
            var result = new HashSet<string>();
            Type type = typeof(DBField);
            // 获取所有公共静态字段（包括常量）
            FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Static);
            // 遍历字段，找到常量并获取其值
            foreach (var field in fields)
            {
                // 判断字段是否为常量
                if (field.IsLiteral && !field.IsInitOnly)
                {
                    string fieldName = field.Name;
                    // 获取常量值
                    var fieldValue = (field.GetValue(null)?.ToString()) ?? string.Empty;
                    if (!string.IsNullOrEmpty(fieldValue) && !result.Contains(fieldValue))
                        result.Add(fieldValue);
                }
            }
            return result;
        }
    }
}
